package org.js.student.service.impl;

import java.util.List;

import com.fasterxml.jackson.core.sym.NameN;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.js.student.domain.FollowForm;
import org.js.student.domain.RepetitionRecordForm;
import org.js.student.domain.dto.ChangeClassDto;
import org.js.student.domain.dto.FollowStudentDto;
import org.js.student.mapper.ClassManageMapper;
import org.js.student.mapper.FollowFormMapper;
import org.js.student.mapper.RepetitionRecordFormMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.js.student.mapper.StudentMapper;
import org.js.student.domain.Student;
import org.js.student.service.IStudentService;

/**
 * 学生Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-05
 */
@Service
public class StudentServiceImpl implements IStudentService 
{
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private RepetitionRecordFormMapper recordFormMapper;
    @Autowired
    private ClassManageMapper classManageMapper;
    @Autowired
    private FollowFormMapper followFormMapper;

    /**
     * 查询学生
     * 
     * @param id 学生主键
     * @return 学生
     */
    @Override
    public Student selectStudentById(Long id)
    {
        return studentMapper.selectStudentById(id);
    }

    /**
     * 查询学生列表
     * 
     * @param student 学生
     * @return 学生
     */
    @Override
    public List<Student> selectStudentList(Student student)
    {
        return studentMapper.selectStudentList(student);
    }

    /**
     * 新增学生
     * 
     * @param student 学生
     * @return 结果
     */
    @Override
    public int insertStudent(Student student)
    {
        return studentMapper.insertStudent(student);
    }

    /**
     * 修改学生
     * 
     * @param student 学生
     * @return 结果
     */
    @Override
    public int updateStudent(Student student)
    {
        return studentMapper.updateStudent(student);
    }

    /**
     * 批量删除学生
     * 
     * @param ids 需要删除的学生主键
     * @return 结果
     */
    @Override
    public int deleteStudentByIds(Long[] ids)
    {
        return studentMapper.deleteStudentByIds(ids);
    }

    /**
     * 删除学生信息
     * 
     * @param id 学生主键
     * @return 结果
     */
    @Override
    public int deleteStudentById(Long id)
    {
        return studentMapper.deleteStudentById(id);
    }

    @Override
    public List<Student> findStudentList(Student student) {
        return studentMapper.findStudentList(student);
    }

    @Override
    public AjaxResult changeClass(ChangeClassDto classDto) {
        RepetitionRecordForm recordForm = new RepetitionRecordForm();
        recordForm.setName(classDto.getName());
        recordForm.setClassId(classDto.getClassId());
        recordForm.setState(classDto.getState());
        recordForm.setNotes(classDto.getNotes());
        recordFormMapper.add(classDto);
//        ClassManage classManage = classManageMapper.selectClassManageById(classDto.getClassId());
//        Integer studentNumber = classManage.getStudentNumber();
//        classManage.setStudentNumber(studentNumber+1);
        Student student = studentMapper.findByName(classDto.getName());
        student.setClassId(classDto.getClassId());
        student.setState(classDto.getState());
        studentMapper.updateStudent(student);
        return AjaxResult.success();
    }

    @Override
    public AjaxResult followStudent(FollowStudentDto studentDto) {
        Student student = followFormMapper.findByName(studentDto.getName());
        if (student==null){
            FollowForm followForm = new FollowForm();
            followForm.setName(studentDto.getName());
            followForm.setTeacherChargeId(studentDto.getTeacherId());
            followForm.setDifficultyCoefficient(studentDto.getDifficultyCoefficient());
            followForm.setNotes(studentDto.getNotes());
            followFormMapper.insertFollowForm(followForm);
            return AjaxResult.success();
        }else {
           return AjaxResult.error("该学生已重点关注");
        }

    }
}
